﻿using AutoMapper;
using B.S.Backtrack.Domain.Entities;
using B.S.Backtrack.ErrorCode;
using B.S.Backtrack.Infrastructure.Interface;
using B.S.Backtrack.Read.API.Application.Command.Product;
using MediatR;

namespace B.S.Backtrack.Read.API.Application.CommandHandler.Product
{
    public class QueryGoodsHandler : IRequestHandler<QueryGoodsCommand, ApiResult<List<Goods>>>
    {
        private readonly IBaseRepository<Goods> goodRep;
        private readonly IMapper mapper;

        public QueryGoodsHandler(IBaseRepository<Goods> goodRep,IMapper mapper)
        {
            this.goodRep = goodRep;
            this.mapper = mapper;
        }
        public Task<ApiResult<List<Goods>>> Handle(QueryGoodsCommand request, CancellationToken cancellationToken)
        {
            ApiResult<List<Goods>> result = new ApiResult<List<Goods>>();
            var list=goodRep.GetAll();
            result.Code = ApiEnums.查询成功;
            result.Msg = ApiEnums.查询成功.ToString();
            result.Data=list.ToList();
            return Task.FromResult(result);
        }
    }
}
